<!DOCTYPE html>
<html>
<head>
<title>xlongwei/pdf</title>
<style type="text/css">
tr {
	text-align: left;
}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var sizePrecision = 2;
var jsonpUrl = "http://115.28.229.158/jsonp/pdf";
function td(book){
	return !book ? "<td></td>" : "<td>"
				+ (book.size < 1024000 ? ("<a target=\"_blank\" href=\"./pdfobject.html#"+book.name+"\" title=\"" + humanSize(book.size) + "\">" + book.name + "</a>")
				: ("<a target=\"_blank\" href=\"./pdfjs.html#"+book.name+"\" title=\"" + humanSize(book.size) + "\">" + book.name + "</a>")
				)
			+ "&nbsp<sub><a target=\"_blank\" href=\"/tool/pdf/"+book.name+"\">⬇"+humanSize(book.size)+"</a></sub>"
			+ "</td>";
}
function tr() {
	var tr = "<tr>";
	for (var i = 0; i < arguments.length; i++) {
		tr += arguments[i];
	}
	return tr + "</tr>"
}
function sortb(book1, book2){
	//return book1.size > book2.size ? 1 : -1;
	return book1.name.localeCompare(book2.name);
}
function humanSize(s) {
	//使用全局变量配置精度
	var p = sizePrecision + 1
	var raw = s
	//单位
	var unit = new Array('B', 'K', 'M', 'G', 'T', 'P', 'E', 'Y')
	var u = 0
	//对大小连除至小于1024，记录次数
	while (s >= 1024) {
		s = s / 1024
		u++
	}
	//太大则不加单位
	if (u > unit.length) {
		s = raw
		u = 0
	}
	//除不尽，四舍五入
	if (!Number.isInteger(s))
		s += Math.pow(10, -p)
	s = s.toString()
	//保留有效数字
	var l = s.indexOf('.')
	if (l != -1)
		s = s.substr(0, l + p)
		//加单位
	return s + unit[u]
}
</script>
</head>
<body>
	<table style="margin:auto">
		<tbody>
		</tbody>
	</table>
	<footer style="text-align:center" title="18810761776@qq.com">Powered By <a href="https://gitee.com/xlongwei/pdf" target="_blank">xlongwei/pdf</a></footer>
	<script type="text/javascript">
		$.ajax({
			url : jsonpUrl,
			type : "GET",
			dataType : "jsonp",
			success : function(data) {
				data = data.sort(sortb);
				for(i=0; i<data.length; i+=3){
					book1 = data[i];
					book2 = i+1<data.length ? data[i+1] : null;
					book3 = i+2<data.length ? data[i+2] : null;
					$("tbody").append(
						tr( td(book1), td(book2), td(book3) )
					);
				}
			}
		});
	</script>
</body>
</html>
